package login;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class Userlogin implements UserInterface{

    //为了让多个对象使用同一个集合，用static修饰一下数组
    public static List<User> arr =new ArrayList<>();
    //private Object objects;

    public static List<User> getArr() {
        return arr;
    }

    public static void setArr(List<User> arr) {
        Userlogin.arr = arr;
    }

    public List<User> getarr() {
        return arr;
    }

    public String getuId(User user)
    {
        return user.uID;
    }

    public User u;
    @Override
    public void showUsers(){
        for(User u:arr)
        {
            System.out.println("用户ID："+u.getID()+"用户账号名："+u.getUsername()+"用户密码"+u.getPassword());
    }
    }

    //返回用户
    public User cast()
    {
        return u;
    }
    //实现登录功能
    @Override
    public boolean isLogin(String username, String password,String ID) {


        for (User user:arr) {

            //if(user.getID().equals(ID)&&user.getPassword().equals(password)&&user.getUsername().equals(username))
            if(Objects.equals(user.getID(),ID)&&Objects.equals(user.username,username)&&Objects.equals(user.password,password))
            {
                u=user;
                return true;
            }
        }
        return false;
    }

    //实现注册功能
    @Override
    public void regist(User user) {
        //添加到数组里
        arr.add(user);
    }
}
